package com.colmmcsky.twit2lj;

import java.util.Calendar;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

public class AutorunBroadcastReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
		Calendar now = Calendar.getInstance();
		boolean isFirst = now.get(Calendar.DAY_OF_MONTH) == 1;
    	
    	SharedPreferences preferences = context.getSharedPreferences(MainActivity.PrefsName, 0);
    	boolean doDaily = preferences.getBoolean(MainActivity.AutoPostKey, true);
    	boolean doMonthly = isFirst && preferences.getBoolean(MainActivity.AutoMonthlyPostKey, true);    	

    	if (doDaily || doMonthly) {
    		PostWorker worker = new PostWorker(null, context, doDaily, doMonthly);      	
    		worker.start();
    	}
    }
}
